# Copyright 2021 Huawei Technologies Co., Ltd
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""Resnet."""

from typing import Any

from mindvision.classification.models.classifiers import BaseClassifier
from mindvision.classification.models.backbones import ResidualBlockBase, ResidualBlock, ResNet
from mindvision.classification.models.head import DenseHead
from mindvision.classification.models.neck import GlobalAvgPooling


def resnet18(num_classes: int = 1000, **kwargs: Any) -> ResNet:
    """Resnet18 structure."""
    backbone = ResNet(ResidualBlockBase, [2, 2, 2, 2], **kwargs)
    neck = GlobalAvgPooling()
    head = DenseHead(input_channel=512, num_classes=num_classes)
    model = BaseClassifier(backbone, neck, head)
    return model


def resnet34(num_classes: int = 1000, **kwargs: Any) -> ResNet:
    """Resnet34 structure."""
    backbone = ResNet(ResidualBlockBase, [3, 4, 6, 3], **kwargs)
    neck = GlobalAvgPooling()
    head = DenseHead(input_channel=512, num_classes=num_classes)
    model = BaseClassifier(backbone, neck, head)
    return model


def resnet50(num_classes: int = 1000, **kwargs: Any) -> ResNet:
    """Resnet50 structure."""
    backbone = ResNet(ResidualBlock, [3, 4, 6, 3], **kwargs)
    neck = GlobalAvgPooling()
    head = DenseHead(input_channel=2048, num_classes=num_classes)
    model = BaseClassifier(backbone, neck, head)
    return model


def resnet101(num_classes: int = 1000, **kwargs: Any) -> ResNet:
    """Resnet101 structure."""
    backbone = ResNet(ResidualBlock, [3, 4, 23, 3], **kwargs)
    neck = GlobalAvgPooling()
    head = DenseHead(input_channel=2048, num_classes=num_classes)
    model = BaseClassifier(backbone, neck, head)
    return model


def resnet152(num_classes: int = 1000, **kwargs: Any) -> ResNet:
    """Resnet152 structure."""
    backbone = ResNet(ResidualBlock, [3, 8, 36, 3], **kwargs)
    neck = GlobalAvgPooling()
    head = DenseHead(input_channel=2048, num_classes=num_classes)
    model = BaseClassifier(backbone, neck, head)
    return model
